<!--废水 sewageDisc-->
<template>
    <Layout>
        <Form ref="queryForm" :model="dataToQuery" :label-width="120">
            <Row v-show="!switchFlag" class="query-form" >
                <Col span="8">
                    <FormItem label="企业名称：" prop="order">
                        <cascader-dom class="query-form-el" ref='queryOrgCascader' @setOrgInfo='setQueryCompanyId' :orgTree="true"
                                      :currentOrgId="dataToQuery.companyId" :setCurrentName="{label:dataToQuery.companyName,value:dataToQuery.companyId}"></cascader-dom>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem label="登记时间：" prop="content" >
                        <DatePicker class="query-form-el" v-model="dataToQuery.dateRange" format="yyyy-MM-dd" type="daterange" placement="bottom-end" placeholder="请选择查询时间段"
                                    @on-change="onSelectQueryDateRange"></DatePicker>
                    </FormItem>
                </Col>
                <Col span="8">
                    <Button @click="switchQuery(true)" class="ivu-btn-switch" type="text">展开∨</Button>
                    <Button @click="reset" class="ivu-btn-reset"  >重置</Button>
                    <Button type="primary" class="ivu-btn-query"   icon="md-search"  @click="query">查询</Button>
                </Col>
            </Row>
            <Row v-show="switchFlag" class="query-form">
                <Col span="8">
                    <FormItem label="企业名称：" prop="belongOrgId">
                        <cascaderDom class="query-form-el" ref="queryOrgCascader1" :orgTree="true"
                                     :currentOrgId = "dataToQuery.belongOrgId"
                                     :setCurrentName="{label:dataToQuery.belongOrgName, value:dataToQuery.belongOrgId}"
                                     @setOrgInfo='(data)=>{cascaderQueryDomIdChangeHandle(data,"belongOrgId");}'
                                     @setOrgname='(data)=>{cascaderQueryDomNameChangeHandle(data,"belongOrgName");}'></cascaderDom>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem label="登记时间：" prop="content" >
                        <DatePicker class="query-form-el" v-model="dataToQuery.dateRange" format="yyyy-MM-dd" type="daterange" placement="bottom-end" placeholder="请选择查询时间段"
                                    @on-change="onSelectQueryDateRange"></DatePicker>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem label='排放类别：' prop='discType'>
                        <Input class="query-form-el" type='text' v-model='dataToQuery.discType'></Input>
                    </FormItem>
                </Col>
            </Row>
            <Row v-show="switchFlag" class="query-form">
                <Col span="8">
                    <FormItem label='采样日期：' prop='sampleDate'>
                        <DatePicker class="query-form-el" v-model="dataToQuery.sampleDateRange" format="yyyy-MM-dd" type="daterange" placement="bottom-end" placeholder="请选择查询时间段"
                                    @on-change="(date) => onSelectFieldQueryDateRange(date, 'sampleDate')"></DatePicker>
                    </FormItem>
                </Col>
                <Col span="8" offset="8">
                    <Button @click="switchQuery(false)" class="ivu-btn-switch" type="text">收起∧</Button>
                    <Button @click="reset" class="ivu-btn-reset">重置</Button>
                    <Button class="ivu-btn-query" icon="md-search" @click="query">查询</Button>
                </Col>
            </Row>
            <Row class="query-form">
                <Col span="24">
                    <Button size="large"  class="ivu-btn-add" icon="md-add"  @click="addInfo">新增</Button>
                </Col>
            </Row>
        </Form>
        <Table ref='table' :height="tableHeight"  no-data-text="没有查询到相关数据!" @on-selection-change = 'getSelectRows' :loading='pageStatus.loading'
               border :columns="columns1"  :data="dataTable" >
        </Table>
        <Row style="margin-right:10px;">
            <Col span="24" >
                <Page style="float: right" :total="pagedata.total" :page-size="pagedata.pageSize" @on-change="pageChange" @on-page-size-change="pageSizeChange" :page-size-opts="pageSizeArray" show-total show-sizer show-elevator />
            </Col>
        </Row>
        <Modal  title="废水排放监测登记" :transfer=false :mask-closable="false" v-model="dialogShow" v-if="dataToView && dialogShow" :width=800 :styles="{height:'688px'}"  class-name='limit-height-dialog' >
            <Row>
                <Col span="24">
                    <Form ref="dialogForm" :class="mode === 'view'?'modal-view-detail':'modal-form'" :show-message="false" :model="dataToView" :rules="mode === 'view'?{} :ruleCustom"  :label-position="mode === 'view'?'right':'top'" :label-width="mode === 'view'?160:null">
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem label='企业名称：' prop='companyId'>
                                    <div v-if="mode === 'view'">{{dataToView.companyName}}</div>
                                    <cascader-dom v-else ref='orgCascader' @setOrgInfo='setCompanyId' @setOrgname="setCompanyName" :orgTree="true" :currentOrgId = "dataToView.companyId" :setCurrentName="{label:dataToView.companyName,value:dataToView.companyId}" ></cascader-dom>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label='污水排放类别：' prop='discType'>
                                    <div v-if="mode === 'view'">{{dataToView.discType}}</div>
                                    <Input v-else type='text' v-model='dataToView.discType'></Input>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label='采样点：' prop='sampleSite'>
                                    <div v-if="mode === 'view'">{{dataToView.sampleSite}}</div>
                                    <Input v-else v-model='dataToView.sampleSite' class="query-form-el"></Input>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label='采样日期：' prop='sampleDate'>
                                    <div v-if="mode === 'view'">{{renderViewDate(dataToView.sampleDate)}}</div>
                                    <DatePicker v-else type="date" placeholder="请选择日期" class="query-form-el" v-model='dataToView.sampleDate'></DatePicker>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label='监测开始日期：' prop='surveyStartDate'>
                                    <div v-if="mode === 'view'">{{renderViewDate(dataToView.surveyStartDate)}}</div>
                                    <DatePicker v-else type="date" placeholder="请选择日期" class="query-form-el" v-model='dataToView.surveyStartDate'></DatePicker>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label='监测结束日期：' prop='surveyEndDate'>
                                    <div v-if="mode === 'view'">{{renderViewDate(dataToView.surveyEndDate)}}</div>
                                    <DatePicker v-else type="date" placeholder="请选择日期" class="query-form-el" v-model='dataToView.surveyEndDate'></DatePicker>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label='标准限值：' prop='standardValue'>
                                    <div v-if="mode === 'view'">{{dataToView.standardValue}}</div>
                                    <InputNumber v-else class="query-form-el" v-model='dataToView.standardValue' :min="0"></InputNumber>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label='监测项目：' prop='surveyItem'>
                                    <div v-if="mode === 'view'">{{dataToView.surveyItem}}</div>
                                    <Input v-else type='text' v-model='dataToView.surveyItem'></Input>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label='监测结果：' prop='registrant'>
                                    <div v-if="mode === 'view'">{{dataToView.surveyResult}}</div>
                                    <InputNumber v-else class="query-form-el" v-model='dataToView.surveyResult' :min="0"></InputNumber>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label='监测频次：' prop='surveyFrequency'>
                                    <div v-if="mode === 'view'">{{dataToView.surveyFrequency}}</div>
                                    <Input v-else type='text' v-model='dataToView.surveyFrequency'></Input>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label='登记人：' prop='registrant'>
                                    <div v-if="mode === 'view'">{{dataToView.registrant}}</div>
                                    <Input v-else type='text' v-model='dataToView.registrant' readonly></Input>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label='登记时间：' prop='registTime'>
                                    <div v-if="mode === 'view'">{{renderViewDate(dataToView.registTime)}}</div>
                                    <DatePicker v-else type="date" placeholder="请选择日期" class="query-form-el" v-model='dataToView.registTime' readonly></DatePicker>
                                </FormItem>
                            </Col>
                            <Col span="11"></Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem label='备注：' prop='notes'>
                                    <div v-if="mode === 'view'">{{dataToView.notes}}</div>
                                    <Input v-else type='textarea' v-model='dataToView.notes'></Input>
                                </FormItem>
                            </Col>
                        </Row>
                    </Form>
                </Col>
            </Row>
            <div slot="footer">
                <Button v-if="mode != 'view'" type="primary"  class='ivu-btn-save' @click="submit('dialogForm')" >确定</Button>
                <Button v-if="mode != 'view'" type="primary"  class='ivu-btn-cancel' @click="handleCancel" >取消</Button>
                <Button v-if="mode === 'view'" class='ivu-btn-save' @click="dialogShow=false">关闭</Button>
            </div>
        </Modal>
    </Layout>
</template>

<script>
    import {Api} from '@/api/index.js'
    import {formatDate} from '@/tools/index'
    import _deepclone from 'lodash/cloneDeep'
    var cascaderDom = () => import('@/components/cascader-dom.vue');
    import pageCommonFunction from '@/components/pageCommonFunction.js'
    export default {
        components:{
            cascaderDom
        },
        data(){
            return {
                ...this.createCommonDataField(),
                columns1: [
                    { title: '序号', width: 80, fixed: 'left', align: 'center', render: this.indexColumnsRender},
                    { key:'companyName',title: '企业名称',  align: 'center', minWidth: 220},
                    { key:'discType',title: '排放类别',  align: 'center', width: 150},
                    { key:'sampleSite',title: '采样点',  align: 'center', width: 150 },
                    { key:'sampleDate',title: '采样时间',  align: 'center', width: 100, render: this.renderCellDate  },
                    { key:'surveyStartDate',title: '监测开始日期',  align: 'center', width: 120, render: this.renderCellDate },
                    { key:'surveyEndDate',title: '监测结束日期',  align: 'center', width: 120, render: this.renderCellDate },
                    { key:'standardValue',title: '标准限值',  align: 'center', width: 150 },
                    { key:'surveyItem',title: '监测项目',  align: 'center' , width: 150 },
                    { key:'surveyResult',title: '监测结果',  align: 'center', width: 150  },
                    { key:'surveyFrequency',title: '监测频次',  align: 'center', width: 150  },
                    { key:'registrant',title: '登记人',  align: 'center', width: 120  },
                    { key:'registTime',title: '登记时间',  align: 'center', width: 120, render: this.renderCellDate },
                    this.getActionColumns()
                ],
                ruleCustom : {
                    companyId: [ { required: true, message: '请填写企业名称', trigger: 'change' } ],
                    standardValue: [
                        { pattern: /^([0-9][0-9]*)+(.[0-9]{1,4})?$/, message: '排放浓度限值（dB）必须为数字', trigger: 'change',type:'number'}
                    ],
                    surveyResult: [
                        { pattern: /^([0-9][0-9]*)+(.[0-9]{1,4})?$/, message: '排放限值（dB）必须为数字', trigger: 'change',type:'number'}
                    ]
                },
                tableHeight:10,
                // api
                queryUrl:Api.queryWasteSewage,
                deleteUrl:Api.deleteWasteSewage,
                bthDeleteUrl:Api.batchDeleteWasteSewage,
                getUrl:Api.getWasteSewage,
                updateUrl:Api.updateWasteSewage,
                saveUrl:Api.saveWasteSewage,
            }
        },
        mounted() {
             this.setTableHeight();
            this.query();
        },
        methods:{
            ...pageCommonFunction,
            deleteData(params) {
                this.deleteDateAjax(params);
            },
            query() {
                this.queryAjax();
            },
            submit(name) {
                this.submitAjax(name);
            },
            createEmptyDataToAdd() {
                return {
                    standardValue:'',
                    surveyResult:'',
                    registrant: this.currentUser.userName,
                    registTime: new Date()
                }
            }
        },
        watch:{
        },

    }
</script>

<style lang='css' scoped>

</style>
